#ifndef _TAOBAOAPI_TBWORKER_H_
#define _TAOBAOAPI_TBWORKER_H_

#include "http.h"
#include "tcpclient.h"

struct TBRequest
{
    TBRequest();

    string& ToRequest();

    string _secret;
    string _app_key;

    string _fields;
    string _method;
    string _session;

    string _timestamp;
    string _v;

    const string _url;
    const string _format;
    const string _sign_method;

    string _httpmethod;

    string _request;
};

struct TBResponse
{
    TBResponse(){}

    void ToResponse(string& response);

    string _response;    
};

class CTBSyncWorker : public CSyncTcpClient
{
public:

    CTBSyncWorker(const char* appkey, const char* secret, bool istest = false);

    ~CTBSyncWorker(){}

    void SetRequest(TBRequest& param, string fields, string method, string session, string httpmethod = "GET");

    bool Work(TBRequest& request, TBResponse& response);

    virtual int OnRecvMsg(const char* inbuf, int inlen);

private:

    string m_host;
    string m_appkey;
    string m_secret;

    char m_hostheader[32];

    RecvBlockQueue m_recvqueue;
};

#endif //_TAOBAOAPI_TBWORKER_H_
